package com.douxg.fastCoding.spring.exception;

import com.douxg.fastCoding.spring.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description 全局异常
 * 详情参考类WebErrorController
 * @Auther douxg
 * @Date 2020/4/16 14:26
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BizException.class)
    public Result bizHandle(BizException e) {
        log.error("全局异常", e);
        return Result.bizCode(e.getBizCode());
    }

    @ExceptionHandler(BizRuntimeException.class)
    public Result bizRunTimeHandle(BizRuntimeException e) {
        log.error("全局异常", e);
        return Result.bizCode(e.getBizCode());
    }

    @ExceptionHandler(Exception.class)
    public Result bizHandle(Exception e) {
        log.error("全局异常", e);
        return Result.error();
    }
}
